package gui.panels;

import javax.swing.GroupLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.LayoutStyle;

public abstract class Planche extends JPanel{

	private static final long serialVersionUID = 1L;
	
	public final GroupLayout					layout;
	private final GroupLayout.ParallelGroup		horizontalGroup;
	private final GroupLayout.SequentialGroup	verticalGroup;
	
	public Planche()
	{
		super();

		layout = new GroupLayout(this);
		setLayout(layout);
		horizontalGroup = layout
				.createParallelGroup(GroupLayout.Alignment.LEADING);
		verticalGroup = layout.createSequentialGroup();
		layout.setHorizontalGroup(horizontalGroup);
		layout.setVerticalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(verticalGroup));
		verticalGroup.addContainerGap();
		initComponents();
	}

	public abstract String getNom () ;
	
	protected abstract void initComponents();

	public void addComponent(JComponent p)
	{
		horizontalGroup.addComponent(p);
		verticalGroup.addComponent(p);
		verticalGroup.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
	}

	public void addComponent(JComponent p, int marge)
	{
		horizontalGroup.addGroup(layout.createSequentialGroup().addGap(marge,
				marge, marge).addComponent(p).addContainerGap(marge, marge));
		verticalGroup.addComponent(p);
		verticalGroup.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
	}

	public void addSeparator()
	{
		JSeparator js = new JSeparator();
		js.setOpaque(false);
		horizontalGroup.addComponent(js);
		verticalGroup.addComponent(js, GroupLayout.PREFERRED_SIZE,
				GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
		verticalGroup.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
	}

	public void addInterstice()
	{
		verticalGroup.addContainerGap(1, Short.MAX_VALUE);
	}

	public void addEspace(int hauteur)
	{
		verticalGroup.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
				hauteur, hauteur);
	}
	
	public void actionOuverture(){
		
	}
	
	public boolean estValide() {
		return true;
	}
	
	public static abstract class CmdInstanciation
	{
		public abstract Planche getInstance();
	}

}
